package com.qersoft.service;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qersoft.dao.ScoreDao;
import com.qersoft.entity.UserPaperAnswerEntity;
import com.qersoft.entity.userAnswer;
import com.qersoft.util.ScoreUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;


@Service("ScoreService")
public class ScoreImpl extends ServiceImpl<ScoreDao, UserPaperAnswerEntity>
        implements ScoreService {

    @Autowired
    private ScoreDao scoreDao;
    @Autowired
    private QuestionBankService questionBankService;

    public ScoreImpl(ScoreDao scoreDao){
        this.scoreDao = scoreDao;
    }

    @Override
    public ArrayList<Integer> result(ArrayList<userAnswer> userAnswers) {
        int score=0;
        int length=userAnswers.size();
        ArrayList<Integer> arrayList=new ArrayList<>();
        for(int i=0;i<length;i++){
            userAnswer user_Answer=userAnswers.get(i);
            Long id=user_Answer.getId();
            int temp =ScoreUtils.score(user_Answer.getAnswer(),
                    questionBankService.getQuestionBankById(id).getAnswer(),3,5,2,questionBankService.getQuestionBankById(id).getType());
            arrayList.add(temp);
            score+=temp;
        }
        arrayList.add(score);
        return arrayList;
    }
}
